/********************************************************************************
*                 Copyright (C) 2011 - Las Venturas Playground                  *
*                      http://iv-mp.nl | http://lvp-iv.com                      *
*                                                                               *
*    This program is free software: you can redistribute it and/or modify       *
*    it under the terms of the GNU General Public License as published by       *
*    the Free Software Foundation, either version 3 of the License, or          *
*    (at your option) any later version.                                        *
*                                                                               *
*    This program is distributed in the hope that it will be useful,            *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
*    GNU General Public License for more details.                               *
*                                                                               *
*    You should have received a copy of the GNU General Public License          *
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
*                                                                               *
*********************************************************************************
*                                                                               *
*  Las Venturas Playground - Core/IRC.nut                                       *
*                                                                               *
*  Everything related to the IRC ECHO is located here.                          *
*                                                                               *
********************************************************************************/

/*

IV:MP IRC Module v1.0

Basic example script (Beta 1)

*/

local iBot;
local strEchoChannel = "#LVP.IV";

//
// Define the server, port, nickname, realname, ident, ssl.
//
function onScriptInit()
{
    ircRegisterMe();
    iBot = ircConnect("irc.gtanet.com", 6667, "LVP_IV", "LVP_IV", "LVP_IV", false, "");
    return true;
}
addEvent("scriptInit", onScriptInit);

//
// Join the IRC channel
//
function ircOnConnect(iBotid)
{
    print("connect");
    ircJoinChannel(iBotid, strEchoChannel);
    return true;
}

//
// I have no clue.
//
function ircOnReceiveRaw(botid, data)
{
    return true;
}

//
// Show a new connection at IRC.
//
function onPlayerConnect(playerid)
{
    ircSay(iBot, strEchoChannel, "02[" + playerid + "] 03*** " + getPlayerName(playerid) + " has joined the server.");
    return true;
}
addEvent("playerConnect", onPlayerConnect);

//
// Show the disconnect reason at IRC.
//
function onPlayerDisconnect( playerid, reason )
{
    // We set the disconnect reason.
    local sDisconnectReason = "Quit";
    
    if( reason == 1 )
    {
        sDisconnectReason = "Timeout/Crash";
    }
    
    // Inform the rest of the players
    ircSay(iBot, strEchoChannel, "02[" + playerid + "] 03*** " + getPlayerName(playerid) + " has left the server (" + sDisconnectReason + ").");
    return 1;
}
addEvent("playerDisconnect", onPlayerDisconnect);

//
// Show the in-game chat at IRC.
//
function onPlayerText(playerid, text)
{
    ircSay(iBot, strEchoChannel, "02["+playerid+"] 07" + getPlayerName(playerid) + ": " + text);
    return true;
}
addEvent("playerText", onPlayerText);

//
// Show a death message at IRC.
//
function onPlayerDeath(playerid, killerid)
{
    //    sendMessageToAll(getPlayerName(killerid) + " Has killed " + getPlayerName(playerid) + " with a " + WeaponNames[getPlayerWeapon(killerid)] + " (Distance: " + getDistanceBetweenPoints3D(pos1[0], pos1[1], pos1[2], pos2[0], pos2[1], pos2[2]) + " ft)", COLOR_GREEN);
    ircSay(iBot, strEchoChannel, "04*** " + getPlayerName(playerid) + " (ID:"+playerid+") died.");
    return 1;
}
addEvent("playerDeath", onPlayerDeath);

//
// Show IRC chat in-game.
//
//function ircOnUserSay(botid, receiver, user, host, message)
//{
//    sendMessageToAll("[irc] <" + user + "> " + message, 0xFFFFFFAA);    
//    return true;
//}
